package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsGrouponMapper;
import com.qf.pojo.DtsGroupon;
import com.qf.service.DtsGrouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @version 1.0
 * @auther Administrator
 * @date 2023/2/25 9:39
 */
@Service
public class DtsGrouponServiceImpl implements DtsGrouponService {

    @Autowired
    private DtsGrouponMapper dtsGrouponMapper;

    @Override
    public IPage<DtsGroupon> findListByQuery(String goodsId, String sort, String order, Integer page, Integer limit) {
        return dtsGrouponMapper.selectPage(new Page<DtsGroupon>(page,limit)
                ,new QueryWrapper<DtsGroupon>()
                        .eq(!StringUtils.isEmpty(goodsId),"goods_id",goodsId)
                        .orderBy(!StringUtils.isEmpty(sort),"ASC".equalsIgnoreCase(order),sort)
        );
    }

    @Override
    public DtsGroupon create(DtsGroupon dtsGroupon) {
        dtsGrouponMapper.insert(dtsGroupon);
        return dtsGroupon;
    }
}
